import Opt from '@/components/dt/info/Opt.js'

class PersonColumn extends Opt {

  constructor(name, type, change) {
    super()
    this.name = name
    this.type = type
    this.change = change
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [{
        type: 'index',
        title: '序号',
        minWidth: 50,
      },
      {
        field: 'workNo',
        title: '工号',
        minWidth: 90
      },
      {
        field: 'userName',
        title: '姓名',
        minWidth: 90,
      },
      {
        field: 'jobStatusStr',
        title: '在职状态',
        minWidth: 90,
      },
      {
        field: 'postName',
        visible: this.type != 'YEAR_END',
        title: '岗位',
        minWidth: 90,
      },
      {
        field: 'preBonusAmount',
        title: '预发奖金(元)',
        minWidth: 150,
        visible: this.type == 'STANDARD',
        cell: {
          text: {
            type: 'number'
          }
        }
      },
      {
        field: 'yearSettlementAmount',
        title: '年度已结奖金(元)',
        minWidth: 150,
        visible: this.type == 'YEAR_END',
        cell: {
          text: {
            type: 'number'
          }
        }
      },
      {
        field: 'yearSettlementAlreadyAmount',
        title: '年底结算奖金(元)',
        minWidth: 150,
        visible: this.type == 'YEAR_END',
        cell: (info) => {
          return {
            btn: {
              title: String(info.yearSettlementAlreadyAmount).replace(/\B(?=(\d{3})+(?!\d))/g, ','),
              event: 'onPerson'
            }
          }
        }
      },
      {
        field: 'bonusAmount',
        title: '结算奖金(元)',
        minWidth: 150,
        visible: this.type != 'SPECIAL' && this.type != 'YEAR_END',
        cell: {
          text: {
            type: 'number'
          }
        }
      },
      {
        field: 'orderAdjustBonus',
        title: '房源调整(元)',
        minWidth: 150,
        visible: this.type != 'SPECIAL' && this.type != 'YEAR_END',
        cell: {
          text: {
            type: 'number'
          }
        }
      },
      {
        field: 'agentAdjustBonus',
        title: '代理费调整(元)',
        minWidth: 150,
        visible: this.type == 'STANDARD' || this.type == 'DEPOSIT' || this.type == 'SKIP_POINT',
        cell: {
          text: {
            type: 'number'
          }
        }
      },
      {
        field: 'adjustAmount',
        title: '调整金额(元)',
        minWidth: 150,
        visible: this.type != 'SPECIAL',
        cell: (info) => {
          if (this.name == 'billEdit' && info.isCanAdjust != false) {
            return {
              edit: {
                input: {
                  type: 'number',
                  blur: () => {
                    this.change(info)
                  }
                }
              }
            }
          } else {
            return {
              text: {
                type: 'number'
              }
            }
          }
        }
      },
      {
        field: 'radioStr',
        title: '调整金额发放比例',
        minWidth: 160,
        visible: this.type != 'SPECIAL' && this.type != 'HANDOVER' && this.type != 'YEAR_END',
        cell: (info) => {
          if (this.name == 'billEdit' && info.isCanAdjust != false) {
            return {
              edit: {
                select: {
                  options: info.radioStrList.map(i => ({
                    key: i,
                    value: i
                  }))
                },
                change: () => {
                  this.change(info)
                }
              }
            }
          } else {
            return {
              text: {}
            }
          }
        }
      },
      {
        field: 'shouldBonusAmount',
        title: '应付奖金(元)',
        minWidth: 150,
        cell: {
          text: {
            type: 'number',
            show: true
          }
        }
      },
      {
        field: 'bonusPool',
        title: '计提奖金池(元)',
        minWidth: 150,
        cell: {
          text: {
            type: 'number',
            show: true
          }
        }
      },
      {
        field: 'actualBonusAmount',
        title: '实发奖金(元)',
        minWidth: 150,
        cell: {
          text: {
            type: 'number',
            show: true
          }
        }
      },
      {
        field: 'adjustReason',
        title: '调整原因',
        minWidth: 150,
        visible: this.type != 'SPECIAL',
        cell: (info) => {
          if (this.name == 'billEdit' && info.isCanAdjust != false) {
            return {
              edit: {
                placeholder: '请输入调整原因',
                input: {
                  blur: () => {
                    this.change(info)
                  }
                }
              }
            }
          } else {
            return {
              text: {}
            }
          }
        }
      }
    ]
  }
}

export default PersonColumn
